package com.nec.recommend.config.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Objects;

/**
 * 数组的Null值转换
 */
public class ArrayJsonSerializer {

    private ArrayJsonSerializer(){}

    /**
     * 空值Array序列化器
     */
    public static class NullArrayJsonSerializer extends JsonSerializer<Object> {
        @Override
        public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
            if (Objects.isNull(value)) {
                gen.writeStartArray();
                gen.writeEndArray();
            }
        }
    }
}
